// pages/login/login.js
var api = require('../../utils/request')
Page({
    data: {
        userName:'',
        password:'',
        password_str:'',
    },
    onLoad: function (options) {

    },
    onShow: function () {

    },
    getInputuser(data){
        this.setData({
            userName:data.detail.value
        })
    },
    getInputpassword(data){
        let value = data.detail.value;
        var str = '';
        for(var i = 0; i < value.length; i++){
            str += '*'
        }
        this.setData({
            password: value,
            password_str: str
        })
    },
    submit(){
        let username = this.data.userName.trim();
        let password = this.data.password.trim();
        if(!username){
            wx.showToast({
              title: '请输入账号',
              icon:'none'
            })
            return;
        }
        if(!password){
            wx.showToast({
                title: '请输入密码',
                icon:"none"
            })
            return;
        }
        api.postNoToken({
            apiCode: "ILoginService.readerLogin",
            params:{
                username: username,
                password:password
            }      
        }).then(res => {
            console.log("res",res)
            if(res.code == 0){
                 let info = res.data;
                 wx.setStorageSync('info', info);
                 wx.switchTab({
                    url: '../index/index',
                })             
            }else{
                wx.showToast({
                    icon:"none",
                    title: res.msg,
                })
            }
        });
    },
    onHide: function () {

    },
    onReachBottom: function () {

    },
    onShareAppMessage: function () {

    }
})